/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.csc531;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabContentFactory;

import com.csc531.lists.ClassesFatList;
import com.csc531.lists.ClassesThinList;
import com.csc531.lists.NotesThinList;
import com.csc531.maps.WhereAreMyFriends;
import com.csc531.maps.WhereAreMyFriendsMap;

/**
 * @author Javier Figueroa, Abdullah Aldawood, Abdullah Altamami, James McNaul
 *
 * Main of the project. 
 */
public class Manager extends TabActivity implements TabContentFactory {

	private static final String TAG = "Manager";

	//list type
	public static final int CLASSES_FATLIST=0;
	public static final int CLASSES_THINLIST=1;
	public static final int MAP_VIEW=2;
	public static final int DISTANCES_VIEW=3;



	public static enum TabType {
		CLASSES_TAB,
		NOTES_TAB,
		FRIENDS_TAB,
		MAPS_TAB
	}

	//globals
	private boolean _classesTabIsInThinListView = true;
	private boolean _mapTabInMapView = false;

	TabHost _host;

	/* (non-Javadoc)
	 * @see android.app.ActivityGroup#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		_host=getTabHost();  

		Bundle extras = getIntent().getExtras();
		if(extras != null) {
			if(extras.get("TAB") == TabType.CLASSES_TAB) {
				_classesTabIsInThinListView = false;
				switch(extras.getInt("CLASSESVIEWTYPE")) {
				case CLASSES_FATLIST:
					_host.addTab(_host.newTabSpec("one")  
							.setIndicator("Classes")  
							.setContent(new Intent(this, ClassesFatList.class)));
					break;
				case CLASSES_THINLIST:
					_classesTabIsInThinListView = true;
					break;
				}		
			}
		}

		if( _classesTabIsInThinListView ) {
			_host.addTab(_host.newTabSpec("one")  
					.setIndicator("Tasks")  
					.setContent(new Intent(this, ClassesThinList.class)));   
		}             

		_host.addTab(_host.newTabSpec("two")  
				.setIndicator("Notes") 
				.setContent(new Intent(this, NotesThinList.class))); 


		_host.addTab(_host.newTabSpec("three")  
				.setIndicator("Friends")  
				.setContent(new Intent(this, Friends.class))); 

		if(extras != null) {
			if(extras.get("TAB") == TabType.MAPS_TAB) {
				_mapTabInMapView = true;
				switch(extras.getInt("MAPVIEW")) {
				case MAP_VIEW:
					_host.addTab(_host.newTabSpec("four")  
							.setIndicator("Maps")  
							.setContent(new Intent(this, WhereAreMyFriendsMap.class)));
					//_host.setCurrentTabByTag("four");
					break;
				case DISTANCES_VIEW:
					_mapTabInMapView = false;
					break;
				}
				
			}
		}
		
		
		if( _mapTabInMapView == false ) {
			_host.addTab(_host.newTabSpec("four")  
					.setIndicator("Maps")  
					.setContent(new Intent(this, WhereAreMyFriends.class))); 
		}
		
		if(extras != null && 
				(extras.get("TAB") == TabType.MAPS_TAB) ) {
			_host.setCurrentTabByTag("four");
		}
	}  
	/** {@inheritDoc} */
	public View createTabContent(String tag) {
		final TextView tv = new TextView(this);
		tv.setText("Content for tab with tag " + tag);
		return tv;
	}
} 

